/*
 * @Author: your name
 * @Date: 2021-05-24 14:26:11
 * @LastEditTime: 2021-07-28 11:37:43
 * @LastEditors: 陈攀
 * @Description: In User Settings Edit
 * @FilePath: /base-framework-web/src/services/login.ts
 */
import { Base64 } from 'js-base64';
import CryptoJs from 'crypto-js';
import { RequestApi } from '@/net/common/API';

// export type LoginParamsType = {
//   userName: string;
//   password: string;
//   mobile: string;
//   captcha: string;
// }; .ciphertext.words
// eupsi#2020swcare s$eupsi@2020trav elsky
export async function loginHandle(params: any) {
  let encryptPWD = CryptoJs.AES.encrypt(
    params.password,
    CryptoJs.enc.Utf8.parse('eupsi#2020swcare'),
    {
      mode: CryptoJs.mode.CBC,
      iv: CryptoJs.enc.Utf8.parse('s$eupsi@2020trav'),
      padding: CryptoJs.pad.Pkcs7,
    },
  ).toString();
  params.password = encryptPWD;
  let client_id = 'password_auth_mode';
  let client_secret = '123456';
  let base64Str = `${client_id}:${client_secret}`;
  const apiObj = {
    url: '/bf/oauth/token',
    method: 'get',
    params,
    header: {
      Authorization: `Basic ${Base64.encode(base64Str)}`,
    },
  };
  return new RequestApi().getRequest(apiObj);
}
// 获取登录用户的菜单
export async function getMenu(params: any) {
  const apiObj = {
    url: '/bf/uc/auth/menu',
    method: 'get',
    params,
  };
  return new RequestApi().getRequest(apiObj);
}

//退出登录
export async function loginOut() {
  const apiObj = {
    url: '/bf/uc/auth/logout',
    method: 'get',
  };
  return new RequestApi().getRequest(apiObj);
}
